package com.yanxu;

import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;

/**
 * @author 折戟沉沙铁未销
 * @version V1.0
 * @date 2024/5/22-2024
 * @Description: 这里用一句话描述这个类的作用
 */
public class OneWayMessage {
    public static void main(String[] args) throws Exception {
        DefaultMQProducer producer = new DefaultMQProducer("oneway-message-study");
        //定义 NameServer地址
        producer.setNamesrvAddr("139.129.91.21:9876");
        //消息的超时时间
        producer.setSendMsgTimeout(5000);

        producer.start();

        for (int i = 0; i < 10; i++) {
            Message message = new Message(
                    "oneway-message",
                    "tag-oneway",
                    "key-oneway", ("message_" + i).getBytes()
            );

            producer.sendOneway(message); //该方法只管发送，并不关心消息是否发送成功，因此该方法并没有返回值。
        }
    }
}